package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controlador.Controlador;
import Controlador.ControladorRodamiento;
import beans.Rodamiento;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class RodamientosFrame extends Vista {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JFrame ventana = new JFrame();
	
	

	public static void main(String[] args) {
		RodamientosFrame m = new RodamientosFrame();
		Controlador rodamiento=new ControladorRodamiento(m);
		m.addcontroladorrodamiento(rodamiento);
		
	} 
	

	public RodamientosFrame()
	{
		super();
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			{
				jPanel1 = new JPanel();
				ventana.getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				jPanel1.setPreferredSize(new java.awt.Dimension(308, 305));
				ventana.setTitle("Crear Rodamiento");
				{
					txtid = new JLabel();
					jPanel1.add(txtid);
					txtid.setText("Codigo:");
					txtid.setBounds(12, 22, 87, 16);
				}
				{
					txtdesc = new JLabel();
					jPanel1.add(txtdesc);
					txtdesc.setText("Descripcion:");
					txtdesc.setBounds(12, 50, 87, 16);
				}
				{
					txtmarca = new JLabel();
					jPanel1.add(txtmarca);
					txtmarca.setText("Marca:");
					txtmarca.setBounds(12, 117, 87, 16);
				}
				{
					txtorigen = new JLabel();
					jPanel1.add(txtorigen);
					txtorigen.setText("Origen:");
					txtorigen.setBounds(12, 145, 87, 16);
				}
				{
					txtstock = new JLabel();
					jPanel1.add(txtstock);
					txtstock.setText("Stock:");
					txtstock.setBounds(12, 183, 87, 16);
				}
				{
					jButtonaceptar = new JButton();
					jPanel1.add(jButtonaceptar);
					jButtonaceptar.setText("Aceptar");
					jButtonaceptar.setBounds(41, 254, 88, 23);
					jButtonaceptar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButtonaceptarActionPerformed(evt);
						}
					});
				}
				{
					jButtoncancelar = new JButton();
					jPanel1.add(jButtoncancelar);
					jButtoncancelar.setText("Cancelar");
					jButtoncancelar.setBounds(178, 254, 95, 23);
					jButtoncancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButtoncancelarActionPerformed(evt);
						}
					});
				}
				{
					id = new JTextField();
					jPanel1.add(id);
					id.setBounds(137, 19, 109, 23);
				}
				{
					descripcion = new JTextField();
					jPanel1.add(descripcion);
					descripcion.setBounds(137, 47, 109, 23);
				}
				{
					marca = new JTextField();
					jPanel1.add(marca);
					marca.setBounds(137, 114, 109, 23);
				}
				{
					Origen = new JTextField();
					jPanel1.add(Origen);
					Origen.setBounds(137, 142, 109, 23);
				}
				{
					stock = new JTextField();
					jPanel1.add(stock);
					stock.setBounds(137, 180, 109, 23);
				}
				ventana.setLocationRelativeTo(null);
				ventana.setVisible(true);
				ventana.pack();
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void borrarTextos() {
		id.setText("");
		
		descripcion.setText("");
		stock.setText("");
		Origen.setText("");
		marca.setText("");
	}
	private void jButtonaceptarActionPerformed(ActionEvent evt) {
		Rodamiento roda;
		roda=((ControladorRodamiento)getControladorrodamientos()).buscarRodamiento(id.getText());
		if (roda==null) {
			if (id.getText().length()==0 ||  descripcion.getText().length()==0 || Origen.getText().length()==0 || stock.getText().length()==0 || marca.getText().length()==0){
				System.out.println("Debe completar los campos");
			}
			else
			{
			((ControladorRodamiento)getControladorrodamientos()).crearRodamiento(id.getText(),descripcion.getText(), marca.getText(), Origen.getText());
			borrarTextos();
			}
		}

	}
	private JPanel jPanel1;
	private JLabel txtmarca;
	private JTextField id;
	private JTextField descripcion;
	private JButton jButtoncancelar;
	private JButton jButtonaceptar;
	private JTextField stock;
	private JTextField Origen;
	private JTextField marca;
	private JLabel txtstock;
	private JLabel txtorigen;
	private JLabel txtdesc;
	private JLabel txtid;



	public JFrame getVentana() {
		return ventana;
	}


	public void setVentana(JFrame ventana) {
		this.ventana = ventana;
	}
	
	private void jButtoncancelarActionPerformed(ActionEvent evt) {
		this.ventana.dispose();
	}

}
